package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.domain.Reply;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.query.ReplyQueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    /**
     * 获取评论页面的攻略评论
     * @param qo
     * @return
     */
    @GetMapping("/strategy")
    @ResponseBody
    public PageInfo query(CommentQueryObject qo){
        qo.setOrderBy("c.createtime desc");
        PageInfo pageInfo = commentService.query(qo);
        return pageInfo;
    }

    /**
     * 保存一级评论
     * @param comment
     * @return
     */
    @PostMapping("strategy")
    @ResponseBody
    public JSONResult save(Comment comment){
        commentService.save(comment);
        return new JSONResult();
    }

    @GetMapping("/strategy/replys")
    @ResponseBody
    public List<Reply> listReplyAll(ReplyQueryObject qo){
        qo.setOrderBy("r.createtime desc");
        List<Reply> list = commentService.listReplyAll(qo);
        return list;
    }

    /**
     * 保存二级评论
     * @param reply
     * @return
     */
    @PostMapping("strategy/reply")
    @ResponseBody
    public JSONResult saveReply(Reply reply){
        commentService.saveReply(reply);
        return new JSONResult();
    }


    @GetMapping("/counts")
    @ResponseBody
    public int commentCounts(){

        return 0;
    }

}
